package jea.machine.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDesktopPane;
import javax.swing.JMenuItem;

import jea.machine.longitudinalviewers.FrameLongitudinalProfileViewer;
import jea.machine.transverseprofileviewer.FrameLayoutQuery;
import jea.machine.transverseprofileviewer.FrameProfileViewerBySPSLocation;
import jea.machine.transverseprofileviewer.FrameProfileViewerByType;

public class MainGuiMenuListener implements ActionListener 
{
	private JDesktopPane desktop;
	private int insertLocX=0, insertLocY=0;
	
	public MainGuiMenuListener(JDesktopPane desktop)
	{
	   this.desktop = desktop;
	}
	
	@Override
	public void actionPerformed(ActionEvent e)
	{
		 String itemText;	
		   JMenuItem item = (JMenuItem)e.getSource();
		   itemText = item.getText();
		   System.out.println("Item = "+item.getText());	
		   if (  itemText == "Exit" )
			   System.exit(0);
		   
		   
		   if ( itemText == "Search a Vacuum Profile by TYPE..." )
		   {
			FrameProfileViewerByType fpv = new FrameProfileViewerByType();
			fpv.setLocation(insertLocX, insertLocY);
			desktop.add(fpv);
			fpv.toFront();
			insertLocX+=15;
			insertLocY+=10;
			if (insertLocX > 400 ) insertLocX = 0;
			if (insertLocY > 300 ) insertLocY = 0;
		   }
		   
		   if ( itemText == "Search a Vacuum Profile by SPS LOCATION..." )
		   {
			FrameProfileViewerBySPSLocation fpv = new FrameProfileViewerBySPSLocation();
			fpv.setLocation(insertLocX, insertLocY);
			desktop.add(fpv);
			fpv.toFront();
			insertLocX+=15;
			insertLocY+=10;
			if (insertLocX > 400 ) insertLocX = 0;
			if (insertLocY > 300 ) insertLocY = 0;
		   }		   
		   
		   
		   if ( itemText == "Extract a Layout" )
		   {
			FrameLayoutQuery flv = new FrameLayoutQuery();
			flv.setLocation(insertLocX, insertLocY);
			desktop.add(flv);
			flv.toFront();
			insertLocX+=15;
			insertLocY+=10;
			if (insertLocX > 400 ) insertLocX = 0;
			if (insertLocY > 300 ) insertLocY = 0;
		   }		 
		   
		   // TEMPORAIRE
		   if ( itemText == "LONG" )
		   {
			FrameLongitudinalProfileViewer flpv = new FrameLongitudinalProfileViewer();
			flpv.setLocation(insertLocX, insertLocY);
			desktop.add(flpv);
			flpv.toFront();
			insertLocX+=15;
			insertLocY+=10;
			if (insertLocX > 400 ) insertLocX = 0;
			if (insertLocY > 300 ) insertLocY = 0;
		   }
		   		   
	}

}
